//
//  ZyaCarInfoVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2022/3/24.
//  Copyright © 2025 aowang. All rights reserved.
//

import UIKit

class ZyaCarInfoVC: UITableViewController,KSNotData {
    var showView: UIView? {
        return self.tableView
    }
    
    var id_key = ""
    var voc_cd = ""
    var processid = ""
    var todotype = TodoType.normal
    var helper = ZyaTenderHelper()
    var dataArray = [CarInfo]()
    lazy var dateTimePick:DateTimePicker = {
        let v = DateTimePicker()
        return v
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
         let rightBtn = UIButton.creat4Item(title: "返回") { _ in
            self.dismiss(animated: true, completion: nil)
        }
        let right = UIBarButtonItem(customView: rightBtn)
        self.navigationItem.leftBarButtonItem = right
        
        
        self.title = "车辆信息"
        tableView.estimatedRowHeight = 100
        tableView.separatorStyle = .none
        tableView.rowHeight = UITableView.automaticDimension
        
        tableView.tableFooterView = UIView()
        tableView.backgroundColor = Theme.awModuleBgColor
        if #available(iOS 15.0, *) {
            tableView.sectionHeaderTopPadding = 0
        }
        
        
        self.tableView.register(ZyaCarInfoCell.self, forCellReuseIdentifier: ZyaCarInfoCell.identifier)
        tableView.register(GlobalAddTableCell.self, forCellReuseIdentifier: GlobalAddTableCell.identifier)
        
        self.tableView.register(GeneralSepeCell.self, forCellReuseIdentifier: GeneralSepeCell.identifier)
        self.tableView.register(AuditSectinoHeader.self, forHeaderFooterViewReuseIdentifier: AuditSectinoHeader.identifier)
        self.tableView.register(GeneralAuditCell.self, forCellReuseIdentifier: GeneralAuditCell.identifier)
        
        if self.dataArray.count < 1 {
            self.showNotData(with: .notData, text:"",topOffset: -35)
        }else{
            
            self.removeNotDataView()
        }
        
    }
    
    
}

extension ZyaCarInfoVC {
    
    // MARK: - TableView DataSource And Delegate
    override func numberOfSections(in tableView: UITableView) -> Int {
        return dataArray.count
    }
    
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        
        return self.dataArray[section].openx ? 1 : 0
        
        
        
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        let cell = tableView.dequeueReusableCell(withIdentifier: ZyaCarInfoCell.identifier, for: indexPath) as! ZyaCarInfoCell
        
        cell.one = dataArray[indexPath.section]
        
        
        return cell
        
        
        
    }
    
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return 190
        
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        
        
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 50
        
    }
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        
        guard let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: AuditSectinoHeader.identifier) as? AuditSectinoHeader else {
            fatalError()
        }
        let tap = UITapGestureRecognizer()
        tap.numberOfTapsRequired = 1
        tap.addTap { [unowned self] _ in
            
            self.dataArray[section].openx = !self.dataArray[section].openx
            
            let set = IndexSet(integer:section)
            tableView.reloadSections(set, with:UITableView.RowAnimation.automatic)
        }
        
        headerView.addGestureRecognizer(tap)
        var ttt = ""
        ttt = "车辆信息"
     
      
        if self.dataArray[section].openx {
            headerView.arrow.setBackgroundImage(UIImage(named: "arrow_down"), for: .normal)
        } else {
            headerView.arrow.setBackgroundImage(UIImage(named: "arrow_right"), for: .normal)
        }
        
        
        headerView.lab.text = ttt
        
        return headerView
        
    }
    
    
}
